package org.travel_system.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.travel_system.mapper.AdminMapper;
import org.travel_system.pojo.Admin;
import org.travel_system.service.AdminService;
import org.travel_system.utils.Md5Util;

@Service
public class AdminServiceImpl implements AdminService {

    private final AdminMapper adminMapper;

    @Autowired
    public AdminServiceImpl(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    @Override
    public Admin findAdminByName(String adminName) {
        return adminMapper.findAdminByName(adminName);
    }

    @Override
    public int register(String username, String password) {
        //加密
        String md5String = Md5Util.getMD5String(password);
        return adminMapper.register(username, md5String);
    }

    @Override
    public int updateAdminInfo(String username, Admin admin) {
        return adminMapper.updateAdminInfo(username, admin);
    }

    @Override
    public int updatePwd(String username, String newPwd) {
        return adminMapper.updatePwd(username, Md5Util.getMD5String(newPwd));
    }

    @Override
    public Integer findAdminId(String username) {
        return adminMapper.findAdminId(username);
    }

}
